/**
 * @author : Javier Camelis
 */
(function($){
	$.fn.ui_error = function(toggle,icon){
		return this.each(function(){
			$(this).ui_apply('error',toggle || '',icon || 'alert');
		})
	};
	$.fn.ui_header = function(toggle){
		return this.each(function(){
			$(this).ui_apply('header',toggle || '');
		});
	};
	$.fn.ui_light = function(toggle,icon){
		return this.each(function(){
			$(this).ui_apply('light',toggle || '',icon || 'info');
		});
	};
	$.fn.ui_icon = function(toggle,icon){
		return this.each(function(){
			$(this).ui_apply('icon',toggle || '',icon || '' );
		});
	};
	$.fn.ui_apply = function(ui,toggle,icon){
		toggle = toggle || 'add' ;
		icon = icon || '' ;
		return this.each(function(){
			if(toggle=='add'){
				var self = $(this), text = self.text() ;
				this.old = !this.add ? self.html() : this.old ; 
				this.add = true ;
				switch(ui){
					case 'error' : var inner = '<div class="ui-widget"><div class="ui-state-error ui-corner-all" style="padding: 0 .7em;"><p><span class="ui-icon ui-icon-'+icon+'" style="float: left; margin-right: .3em;"></span>'+text+'</p></div></div>' ; 
					break ;
					case 'light' : var inner = '<div class="ui-widget"><div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;"><p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>'+text+'</p></div></div>' ;
					break ;
					case 'header' : var inner = '<span class="ui-widget-header ui-corner-all">'+text+'</span>' ;
					break ;
					case 'icon' : var inner = '<p><span class="ui-icon ui-icon-'+icon+'" style="float: left; margin-right: .3em;"></span>'+text+'</p>'
					break ;
				}
				self.html(inner) ;
			}
			if(toggle=='remove'){
				$(this).html(this.old) ;
				this.add = false ;
			}
		})
	}
})(jQuery);